package com.example.module_motocircle.ui

import com.example.lib_common.base.state.RequestEvent
import com.example.module_motocircle.model.MotoCircleNavigationEnum
import com.example.module_motocircle.model.MotoCircleNavigationItem
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject
import com.example.lib_common.base.BaseViewModel
import com.example.lib_common.base.state.Empty
import com.example.lib_common.base.state.Failed
import com.example.lib_common.base.state.Loading
import com.example.lib_common.base.state.Success



@HiltViewModel
class MotorCircleViewModel @Inject constructor(private val repository: MotorCircleRepository): BaseViewModel() {

    val mNavigationItem = mutableListOf<MotoCircleNavigationItem>() //tab数据
    private val _navigationState = MutableStateFlow<RequestEvent>(Loading) //tab状态
    val navigationState
        get() = _navigationState.asStateFlow()

    /**
     * 获得tab固定导航：应该服务器下发的数据，暂时写死
     */
    fun getFixedNavigationItem() {
        execute(
            action = repository.navigationItem(),
            onStart = {
                _navigationState.value = Loading
            },
            onError = {
                _navigationState.value = Failed(it)
            },
            onFinish = {
                mNavigationItem.clear()
                mNavigationItem.addAll(it.data)
                _navigationState.value = Success

            }
        )


    }


}